import defaultImg from '@/assets/images/200.png'

export const defineDirective = {
  mounted(el: any, binding: any) {
    const observer = new IntersectionObserver(
      ([{ isIntersecting }]) => {
        if (isIntersecting) {
          observer.unobserve(el)
          el.onerror = () => {
            el.src = defaultImg
          }
          el.src = binding.value
        }
      },
      {
        threshold: 0.01
      }
    )
    observer.observe(el)
  }
}
